package com.winit.core.server;

import com.winit.core.server.base.CmdOutputHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

/**
 * Created by wangjian on 16/8/11.
 */
public class RedisServer extends Server {
    private static Logger logger = LoggerFactory.getLogger(RedisServer.class);

    public RedisServer(String ip, String userName, Integer port) throws Exception {
        super(ip, userName, port);
    }

    /**
     * 清空redis
     */
    public void doClean(List<Integer> redisPorts, CmdOutputHandler handler) throws Exception {
        if (redisPorts.size() == 0) {
            throw new Exception("清理redis缓存，redis端口不能为空");
        }
        StringBuffer ports = new StringBuffer();
        for (Integer port : redisPorts) {
            ports.append(port).append(",");
        }
        StringBuffer cmd = new StringBuffer();
        cmd.append("bash /home/beetle/shell/beetle_clean_redis.sh " + ports.toString().substring(0, ports.toString().length() - 1));
        logger.info("com.winit.core.server.RedisServer.doClean cmd:" + cmd);
        this.doExec(handler, cmd.toString());
    }

}
